package org.example.videotran.pojo;


import org.example.videotran.exception.AppExceptionCodeMsg;
import org.springframework.http.HttpStatus;

public class ResponseMessage<T> {

    private Integer code;
    private String message;
    private T data;

    public ResponseMessage(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseMessage success(T data){
        return new ResponseMessage(HttpStatus.OK.value(),"success",data );
    }

    public static <T> ResponseMessage success(){
        return new ResponseMessage(HttpStatus.OK.value(),"success",null );
    }

    public static <T> ResponseMessage fail(){
        return new ResponseMessage(HttpStatus.NO_CONTENT.value(), "fail",null );
    }

    public static <T> ResponseMessage fail(T data){
        return new ResponseMessage(HttpStatus.BAD_REQUEST.value(), "fail",data );
    }

    public static <T> ResponseMessage error(AppExceptionCodeMsg appExceptionCodeMsg){
        ResponseMessage resp = new ResponseMessage(appExceptionCodeMsg.getCode(), appExceptionCodeMsg.getMsg(), null);
        return resp;
    }
    public static <T> ResponseMessage error(int code,String msg){
        ResponseMessage resp = new ResponseMessage(code,msg, null);
        return resp;
    }


    public ResponseMessage() {
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
